//*************************************************************************//
//*           _____   ____________            ______               __     *//
//*          / /__ \ / ____/ ____/           / ____/___  _________/ /     *//
//*     __  / /__/ // __/ / __/    ______   / /_  / __ \/ ___/ __  /      *//
//*    / /_/ // __// /___/ /___   /_____/  / __/ / /_/ / /  / /_/ /       *//
//*    \____//____/_____/_____/           /_/    \____/_/   \__,_/        *//
//*                                                                       *//
//*     Copyright (c) 2006 Ford Argentina. All Rights Reserved.           *//
//*                                                                       *//
//*************************************************************************//

package ar.com.ford.it.webengine.wslx;

import java.lang.reflect.Constructor;
import com.ford.it.logging.ILogger;
import com.ford.it.logging.Level;
import com.ford.it.logging.LogFactory;


/**
 * WslxUserFactory <br>
 * Crea WslxUsers a partir de la clase con la cual fue inicializada la factoria
 * @author Aji
 */
public final class WslxUserFactory  {

    private static String className;
    private static final String CLASS_NAME = WslxUserFactory.class.getName();
    private static final ILogger log = LogFactory.getInstance().getLogger(CLASS_NAME);

    
    private WslxUserFactory() {
    }
    

	/**
	 * Inicializa la factoria
	 * @param initClassName Clase WslxUserXX donde se implementan los metodos abstractos del WslxUser
	 */
    public static void init(String initClassName) {
        String METHOD_NAME = "init";
        
        log.entering(CLASS_NAME, METHOD_NAME, initClassName);
        
        if (className == null || className.equals("")) {
            className = initClassName;
        } 
        
        log.exiting(CLASS_NAME, METHOD_NAME);
    }
     
    
    
	/**
	 * Metodo getClassName.
	 * @return Clase correspondiente para la creacion del WslxUser
	 */
    public static String getClassName() {
        return className;
    }


	/**
	 * Crea el WslxUser para el usuario
	 * @param userId User id
	 * @return WslxUser del usuario
	 */    
    public static WslxUser getWslxUser(String userId) {
        String METHOD_NAME = "getWslxUser";
		WslxUser result;

       	log.entering(CLASS_NAME, METHOD_NAME, userId);


        try {
            Class cls = Class.forName(className);
            Class partypes[] = new Class[1];
            partypes[0] = String.class;
            Constructor ct = cls.getConstructor(partypes);
            Object arglist[] = new Object[1];
            arglist[0] = userId;

            log.exiting(CLASS_NAME, METHOD_NAME);
            result = (WslxUser)ct.newInstance(arglist);
        } catch (Exception excep) {
            log.logp(Level.SEVERE, CLASS_NAME, METHOD_NAME, "Exception: ", excep);
            excep.printStackTrace();
            result = null;
        }
        
        log.exiting(CLASS_NAME, METHOD_NAME, result);
        return result;
    }
    
}